package com.mallotec.android.timenote.data.dao;

import androidx.lifecycle.LiveData;
import androidx.room.Dao;
import androidx.room.Insert;
import androidx.room.OnConflictStrategy;
import androidx.room.Query;
import androidx.room.Update;

import com.mallotec.android.timenote.data.bean.Timenote;

import java.util.List;

/**
 * @author reborn
 * @program TimeNote
 * @description
 * @create 2020-10-28 02:21
 **/
@Dao
public interface TimenoteDao {
    @Query("SELECT * FROM timenote ORDER BY startDatetime desc")
    LiveData<List<Timenote>> getAllTimenotes();

    @Query("SELECT * FROM timenote WHERE endDatetime is null ORDER BY startDatetime desc")
    LiveData<List<Timenote>> getTimenotesByNotEnd();

    @Query("SELECT * FROM timenote WHERE endDatetime is not null ORDER BY endDatetime desc")
    LiveData<List<Timenote>> getTimenotesByIsEnd();

    @Query("SELECT * FROM timenote WHERE id = :timenoteId")
    LiveData<Timenote> findTimenoteById(Integer timenoteId);

    @Insert(onConflict = OnConflictStrategy.REPLACE)
    void insertTimenotes(List<Timenote> timenotes);

    @Insert(onConflict = OnConflictStrategy.REPLACE)
    void insertTimenote(Timenote timenote);

    @Update
    void updateTimenote(Timenote timenote);
}
